﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using PInitiatives.Models;
using System.Web.Security;
using System.Net.Mail;

namespace PInitiatives.Helpers
{
    public static class UserHelper
    {
        public static User GetCurrentUser()
        { 
            PInitiativesEntities db = new PInitiativesEntities();
            return db.Users.SingleOrDefault(u => u.aspnet_Users.UserName == HttpContext.Current.User.Identity.Name);
        }

        //public static MembershipUser GetCurrentAspUser()
        //{
        //    return HttpContext.Current.User;
        //}
        
        public static int GetCurrentUserId()
        {
            if (HttpContext.Current.User.Identity.IsAuthenticated)
            {
                PInitiativesEntities db = new PInitiativesEntities();
                return db.Users.SingleOrDefault(u => u.aspnet_Users.UserName == HttpContext.Current.User.Identity.Name).ID;
            }
            else
                return -1;
        }

        public static User GetUserById(int id)
        {
            PInitiativesEntities db = new PInitiativesEntities();
            return db.Users.SingleOrDefault(u => u.ID == id);
        }

        public static MembershipUser GetMembershipUserByUserId(int id)
        {
            PInitiativesEntities db = new PInitiativesEntities();
            return Membership.GetUser(db.Users.SingleOrDefault(u => u.ID == id).aspnet_Users.UserId);
        }
    }
}